package com.lancoo.lancooknowledgecourseware;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;


/**
 * Created by pengmi on 2018/12/3.
 * Description:
 */

public class KlgAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<KlgModel> klgModelList;

    public KlgAdapter(Context mContext, List<KlgModel> klgModelList) {
        this.mContext = mContext;
        this.klgModelList = klgModelList;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.example_list_item_klg, parent, false);
        KlgVH klgVH=new KlgVH(inflate);
        return klgVH;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        KlgVH klgVH= (KlgVH) holder;
        klgVH.initData(klgModelList.get(position));
    }

    @Override
    public int getItemCount() {
        return klgModelList.size();
    }

    private class KlgVH extends RecyclerView.ViewHolder{

        protected final TextView tv_klg;

        public KlgVH(View itemView) {
            super(itemView);
            tv_klg = itemView.findViewById(R.id.tv_klg);
            tv_klg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(klgModelList.get(getPosition()).getKlgFlag()==0){
//                        if(PermissionsUtil.getInstance(mContext).requestRecorderPermission(mContext)){
//                            LancooKnowledgeManager.getInstance().startKlgCourseWare(mContext,klgModelList.get(getPosition()).getKlgCode(),"http://60.190.136.238:25114/");
//                        }
                    }
                }
            });
        }

        private void initData(KlgModel klgModel){
            tv_klg.setText(klgModel.getKlgName());
        }
    }
}

